<?php
/**
 * Created by 订单类.
 * User: 尚金殿
 * Date: 2018/8/28
 * Time: 14:26
 */

namespace app\admin\controller;


use think\Db;

class OrderController extends CommonController
{
    protected $mysql = 'order';
    protected $pk = 'order_id';
    protected $name = 'phone';
    protected $status = 'order_status';


    //加载列表
    public function lists(){
        $starTime = strtotime($this->request->param('start_time'));
        $endTime = strtotime($this->request->param('end_time'));
        $keyWord = $this->request->param('key_word');
        
        if(!empty($keyWord)){
            //根据手机号查询
            $res = Db::name($this->mysql)->alias('o')->join('t_line l','o.ware_id = l.id')->where('o.phone','like',$keyWord.'%')->where('o.order_status','>',-1)->paginate(10);
        }else if(!empty($starTime)){
            //根据时间查询
            $res = Db::name($this->mysql)->alias('o')->join('t_line l','o.ware_id = l.id')->where('o.create_time','>',$starTime)->where('o.update_time','<=',$endTime)->where('o.order_status','>',-1)->paginate(10);
        }else{

            $res = Db::name($this->mysql)->alias('o')->join('t_line l','l.id = o.ware_id')->where('o.order_status','>',-1)->paginate(10);
        }
	
        //变量输出
        $this->assign(['res'=>$res,'starTime'=>$this->request->param('start_time'),'endTime'=>$this->request->param('end_time'),'key_word'=>$keyWord]);
        //加载模版
        return $this->fetch();
    }

}